// pages/list.js
const search = require('../../lib/search.js');
const sr = new search.Search();
var rule_={};
var keywords_='';

Component({
    properties: {
    },
    data: {
        list: [],
        tip: '下拉加载更多'
    },
    methods: {
        iter({
            keywords=null,
            rule={},
            success=function(){},
            fail=function(){},
            skip=0,
            num=20,
            reset=false
        }) {
            rule_=rule;
            keywords_ = keywords;
            const that=this;
            if (reset) {
                this.setData({
                    tip: '下拉加载更多',
                    list: []
                })
                wx.pageScrollTo({
                    scrollTop: 0
                })
            }
            this.setData({
                tip: '正在加载'
            })
            sr.iter({keywords,rule,success(res){
                that.setData({
                    list: sr.list_,
                    tip: res.length>=20?'下拉加载更多':'已经加载全部'
                });
                success(res);
            }, fail() {
                that.setData({
                    tip: '已经加载全部'
                });
                fail();
            },skip,num,reset});
        },
        toCard(e) {
            console.log('点击事件：',e);
            let password = e.currentTarget.dataset._id;
            let index = e.currentTarget.dataset.index;
            const rl=new search.Rule({
                keywords: keywords_,
                rule: rule_,
                skip: index
            });
            wx.navigateTo({
                url: '../cardIfm/cardIfm?password='+password+'&'+rl.zip,
            })
        },
        showMenu(e) {
            wx.showActionSheet({
                itemList: ['加入主卡组', '加入主卡组', '分享'],
                success(res) {
                    console.log(res.tapIndex)
                },
                fail(res) {
                    console.log(res.errMsg)
                }
            })
        }
    }
})
